FROM  centos:centos7.9.2009 as builder1
ENV DIRPATH=/home
WORKDIR $DIRPATH
COPY . .

RUN set -x \
    && mkdir $DIRPATH/bin \
    && sed -i -e 's|mirrorlist=|#mirrorlist=|g' \
          -e 's|#baseurl=http://mirror.centos.org/centos|baseurl=https://mirrors.ustc.edu.cn/centos|g' \
         /etc/yum.repos.d/CentOS-Base.repo \
    && cp -a $DIRPATH/docker/bin/sansan $DIRPATH/bin \
    && chmod a+x $DIRPATH/bin/sansan \
    && yum install wget gcc -y \
    && wget https://dl.google.com/go/go1.20.2.linux-amd64.tar.gz \
    && tar -zxf go1.20.2.linux-amd64.tar.gz -C /usr/local \
    && export GOROOT=/usr/local/go \
    && export PATH=$PATH:$GOROOT/bin:$GOPATH/bin \
    && go env -w GO111MODULE=on \
    && go env -w GOPROXY=https://goproxy.cn,direct \
    && for x in $(ls ssiot-* -d | grep -v ssiot-ui);do\ 
    cd $DIRPATH/$x \
    && go mod tidy \
    && CGO_ENABLED=1 \ 
    GOOS=linux GOARCH=amd64 \
    go build -o  $DIRPATH/bin/$x \
    -x -ldflags="-w -s" \
    main.go;\
    done 

from node:18.13.0-bullseye-slim as builder2
ENV NODE_OPTIONS="--max_old_space_size=4096"
WORKDIR /home
COPY ./ssiot-ui .
RUN set -x \
   && npm config set registry https://registry.npm.taobao.org \ 
   && npm install \
   && npm run build 

  

from ssiot/base:v0.1.0
COPY  --from=builder1 /home/bin/* /home/ssiot/bin
RUN true
COPY  --from=builder2 /home/dist /home/ssiot/web/sansan  
RUN true 
COPY docker/bin/ss-gw-modbus /home/ssiot/applet/ssiot-gw-modbus-100/
RUN chmod a+x /home/ssiot/applet/ssiot-gw-modbus-100/ss-gw-modbus


